// component/orderbox/orderbox.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    list:{
      type:Array
    },
    type:{
      type:Number
    }
  },
  options: {
    addGlobalClass: true,
  },
  /**
   * 组件的初始数据
   */
  data: {
    active:1,
    checked: false,
    result: [],
    arr:[]
  },
  /**
   * 组件的方法列表
   */
  methods: {
    urgeUser(e){//服务催促
      console.log(e.currentTarget.dataset.phone)
      let telphone = e.currentTarget.dataset.phone;
      if(!telphone){
        wx.showToast({
          title: '该订单没有用户信息！',
          icon: 'none',
          duration: 2000
        })
        return
      }else{
        wx.makePhoneCall({
          phoneNumber: telphone
        })
      }
    },
    //跳转
    orderRouter(e){
      // wx.navigateTo({
      //   url: '/pages/orderFang/orderFang',
      // })
      // console.log(e.currentTarget.dataset)
      var i = e.currentTarget.dataset.active; //订单状态
      var j = e.currentTarget.dataset.status; //房源类型
      var id = e.currentTarget.dataset.id; //订单id
      var time = e.currentTarget.dataset.time; //订单时间
      if(i==2){
        wx.navigateTo({url: '/pages/orderSbai/orderSbai?id='+ id +'&time='+time+'&type='+j});
      }else{
        switch(j){
          case 2:
            // 折扣签约
            wx.navigateTo({url: '/pages/orderQyue/orderQyue?id='+ id +'&time='+time});break;
          case 3:
            // 放盘签约
            wx.navigateTo({url: '/pages/orderFang/orderFang?id='+ id +'&time='+time});break;
          case 1:
            // 优选签约
            wx.navigateTo({url: '/pages/orderPpay/orderPpay?id='+ id +'&time='+time});break;
            case 4:
            // 增值签约
            wx.navigateTo({url: '/pages/orderZzhi/orderZzhi?id='+ id +'&time='+time});break;
        }
      }
      // if(j==4){
      //   wx.navigateTo({
      //     url: '/pages/orderSbai/orderSbai',
      //   })
      // }else{
      //   switch(i){
      //     case 0:
      //       wx.navigateTo({url: '/pages/orderFang/orderFang',});break;
      //     case 1:
      //       wx.navigateTo({url: '/pages/orderQyue/orderQyue',});break;
      //     case 2:
      //       wx.navigateTo({url: '/pages/orderPpay/orderPpay',});break;
      //   }
      // }
    },
    onChange(event) {
      this.setData({
        result: event.detail,
      });
      this.triggerEvent('onChange',event.detail);
      // console.log(event.detail)
    },
    del(){
      this.setData({
        result:[]
      })
    },
    queryall(){
      this.properties.list.forEach(element => {
        // console.log(element.id);
        this.data.arr.push(element.id.toString());
      });
      this.setData({
        result:this.quchong(this.data.arr)
      })
      // console.log(this.data.result);
    },
    quchong(arr){
      var tempArr = []; //返回的值
      var indexArr= []; //返回的索引
        for (var i = 0; i < arr.length; i++) {
          if (tempArr.indexOf(arr[i]) == -1) {
            tempArr.push(arr[i]);
            indexArr.push(i)
          } else if (tempArr.indexOf(arr[i])>=0){
            for(var j = 0;j<tempArr.length;j++){
            if (tempArr[j] == arr[i]) {
              tempArr.splice(j, 1, tempArr[j]);
              indexArr.splice(j, 1, i);
            }
          }
        }
      }
      return tempArr
    },
  },
})
